﻿using AntQuartzUI.Services;
using Quartz;
using Quartz.Listener;

namespace AntQuartzUI;

public class TriggerExecutionMonitor : TriggerListenerSupport,ITriggerListener
{
    private readonly IQuartzService _quartzService;
    
    public TriggerExecutionMonitor(IQuartzService quartzService)
    {
        _quartzService = quartzService;
    }
    
    public override string Name => nameof(TriggerExecutionMonitor);

    public override Task TriggerFired(ITrigger trigger, IJobExecutionContext context,
        CancellationToken cancellationToken = new CancellationToken())
    {
        _quartzService.FireCountsDic[trigger.Key] = _quartzService.FireCountsDic.GetOrAdd(trigger.Key, 0) + 1;
        return Task.CompletedTask;
    }
}